package com.yc.video.ui.view

import android.content.Context
import android.text.format.Formatter
import com.lxj.xpopup.core.BasePopupView
import com.salton123.soulove.app.R
import com.salton123.soulove.sailfish.db.SailfishDatabase
import com.salton123.soulove.utils.Utils
import com.yc.video.bridge.ControlWrapper
import kotlinx.android.synthetic.main.popup_view_video_info.view.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 * Time:2021/10/9 17:00
 * Author:
 * Description:
 */
class VideoInfoPopupView(var mControlWrapper: ControlWrapper, context: Context) : BasePopupView(context) {
    override fun getPopupLayoutId(): Int = R.layout.popup_view_video_info
    override fun onCreate() {
        super.onCreate()
        MainScope().launch {
            SailfishDatabase.Impl.videoDao().loadItem(mControlWrapper.url)?.let {
                withContext(Dispatchers.Main) {
                    tvName.text = it.name
                    tvPath.text = context.getString(R.string.path).plus(it.filePath)
                    tvDuration.text = context.getString(R.string.duration).plus(Utils.formatTime(it.duration))
                    tvMore.text = "${it.width}x${it.height} ".plus(Formatter.formatFileSize(context, it.size))
                }
            }
        }

    }

}